<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<!-- 下拉框 -->
<link rel="stylesheet" href="static/ace/css/chosen.css" />
<!-- jsp文件头和头部 -->
<%@ include file="../../system/index/top.jsp"%>
<!-- 日期框 -->
<link rel="stylesheet" href="static/ace/css/datepicker.css" />
<link rel="stylesheet" href="static/ace/css/bootstrap-tagsinput.css" />
<link href="static/cropper/cropper.min.css" rel="stylesheet">
<link href="static/cropper/sitelogo.css" rel="stylesheet">
</head>
<body class="no-skin">
	<!-- /section:basics/navbar.layout -->
	<div class="main-container" id="main-container">
		<!-- /section:basics/sidebar -->
		<div class="main-content">
			<div class="main-content-inner">
				<div class="page-content">
					<div class="row">
						<div class="col-xs-12">

							<form action="admin/article/${msg }.do" name="Form" id="Form" method="post">
								<input type="hidden" name="id" value="${entity.getId()}" />
								<div id="zhongxin" style="padding-top: 13px;">
									<table id="table_report" class="table table-striped table-bordered table-hover">
										<tr>
											<td style="width: 150px; text-align: right; padding-top: 13px;">标题:</td>
											<td>
												<input class="notEmpty" type="text" name="title" value="${entity.getTitle()}" maxlength="255" placeholder="这里输入标题" title="标题" style="width: 98%;" />
											</td>
										</tr>
										<tr>
											<td style="width: 150px; text-align: right; padding-top: 13px;">标签:</td>
											<td>
												<input id="ipt_tags" name="tags" type="text" value="${entity.tags }" title="这里输入标签" maxlength="20" data-role="tagsinput" style="width: 98%;">
											</td>
										</tr>
										<tr>
											<td style="width: 150px; text-align: right; padding-top: 13px;">简介:</td>
											<td>
												<textarea class="notEmpty" name="brief" rows="4" maxlength="100" style="width: 98%;">${entity.brief } </textarea>
											</td>
										</tr>
										<tr>
											<td style="width: 125px; text-align: right; padding-top: 13px;">商品展示图:</td>
											<td>
												<div class="ibox-content">
													<div class="row">
														<div class="col-md-9" style="height: 120px">
															<img id="img_img" src="${entity.img }" width="120px" height="120px">
														</div>
														<div id="crop-avatar" class="col-md-3">
															<a class="btn avatar-view">点击上传</a>
															<input id="hidden_img" type="hidden" name="img" value="${entity.img }" />
														</div>
													</div>
												</div>

											</td>
										</tr>
										<tr>
											<td style="width: 150px; text-align: right; padding-top: 13px;">内容:</td>

											<td>
												<script id="content" name="content" type="text/plain" style="width: 88%; height: 500px;"></script>
											</td>
										</tr>

										<tr>
											<td style="text-align: center;" colspan="10">
												<a class="btn btn-mini btn-primary" onclick="save();">保存</a>
												<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
											</td>
										</tr>
									</table>
								</div>
								<div id="zhongxin2" class="center" style="display: none">
									<br />
									<br />
									<br />
									<br />
									<br />
									<img src="static/images/jiazai.gif" />
									<br />
									<h4 class="lighter block green">提交中...</h4>
								</div>
							</form>
						</div>
						<!-- /.col -->
					</div>
					<!-- /.row -->
				</div>
				<!-- /.page-content -->
			</div>
		</div>
		<!-- /.main-content -->
	</div>
	<!-- /.main-container -->
	<!-- 图片上传 -->
	<div class="modal fade" id="avatar-modal" aria-hidden="true" aria-labelledby="avatar-modal-label" role="dialog" tabindex="-1">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<form class="avatar-form" action="/admin/file/upload" enctype="multipart/form-data" method="post">
					<div class="modal-header">
						<button class="close" data-dismiss="modal" type="button">&times;</button>
						<h4 class="modal-title" id="avatar-modal-label">上传图片</h4>
					</div>
					<div class="modal-body">
						<div class="avatar-body">
							<div class="avatar-upload">
								<input class="avatar-src" name="avatar_src" type="hidden">
								<input class="avatar-data" name="avatar_data" type="hidden">
								<label for="avatarInput">图片上传</label>
								<input class="avatar-input" name="upfile" type="file" accept="image/*">
							</div>
							<div class="row">
								<div class="col-md-9">
									<div class="avatar-wrapper"></div>
								</div>
								<div class="col-md-3">
									<div class="avatar-preview preview-lg"></div>
									<div class="avatar-preview preview-md"></div>
									<div class="avatar-preview preview-sm"></div>
								</div>
							</div>
							<div class="row avatar-btns">
								<div class="col-md-9"></div>
								<div class="col-md-3">
									<button class="btn btn-success btn-block avatar-save" type="button" data-crop-id="crop-avatar" onclick="uploadPhoto(this);">
										<i class="fa fa-save"></i>
										保存修改
									</button>
								</div>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
	<!-- 图片上传 -->

	<!-- 页面底部js¨ -->
	<%@ include file="../../system/index/foot.jsp"%>
	<!-- 下拉框 -->
	<script src="static/ace/js/chosen.jquery.js"></script>
	<script src="/static/ace/js/bootbox.js"></script>
	<!-- 日期框 -->
	<script src="static/ace/js/date-time/bootstrap-datepicker.js"></script>
	<script src="static/ace/js/bootstrap-tagsinput.js"></script>
	<!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
	<script type="text/javascript" src="static/js/common/common.js"></script>
	<script type="text/javascript" src="static/js/common/commonTip.js"></script>
	<script type="text/javascript" src="static/js/common/myValidation.js"></script>
	<!-- 百度编辑框 -->
	<script src="plugins/ueditor/ueditor.config.js"></script>
	<script src="plugins/ueditor/ueditor.all.js"></script>
	<!-- 百度编辑框 -->

	<script src="static/cropper/cropper.min.js"></script>
	<script src="static/cropper/sitelogo2.js"></script>
	<script type="text/javascript" src="static/js/jquery-form.js"></script>
	<script type="text/javascript">
		$(function() {
			top.hangge();
			var ue = UE.getEditor('content', {
				initialFrameHeight : 200,
				initialContent: '${entity.content}'
			});
			new CropAvatar($('#crop-avatar'), "avatar-modal", 1.33);
		});
		//保存
		function save() {
			if (!myValidation.commonValid("Form")) {
				return false;
			}
			if($("#hidden_img").val().length == 0){
				bootbox.alert("请上传图片");
				return;
			}
			$("#zhongxin").hide();
			$("#zhongxin2").show();
			$.post("/admin/article/${msg}", $("#Form").serialize(),function(result){
				if(result.code == 200){
					bootbox.alert("成功", function(){
						top.Dialog.close();
					});
				}else{
					bootbox.alert(result.mes);
				}
				$("#zhongxin").show();
				$("#zhongxin2").hide();
			})
			
		
		}
		function uploadPhoto(o) {
			top.jzts();
			var $form = $(o).closest(".avatar-form");
			var $modal = $(o).closest(".modal");

			$form.ajaxSubmit(function(result) {
				if (result.code == 200) {
					$("#img_img").attr("src",  result.data.url);
					$("#hidden_img").val(result.data.url);
					$modal.modal('hide');
				} else {
					bootbox.alert("上传失败");
				}

				top.hangge();
			})
		}
		$(function() {
			//日期框
			$('.date-picker').datepicker({
				autoclose : true,
				todayHighlight : true
			});
		});
	</script>
</body>
</html>